package com.qf.Utils;

import com.qf.entity.Admin;
import com.qf.entity.Student;
import com.qf.entity.StudentClass;

import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class DaoUtils {
    private static List<Admin>     admins      = new ArrayList<>();
    private static List<Student>   students    = new ArrayList<>();
    //学生班级管理
    private  static List<StudentClass> studentClasses = new ArrayList<>();
    //班级人数管理
    private  static int[] size={0,0,0};

    //img加载到的路径
    public  static String file = "D:/uploader/";

    static{
        admins.add(new Admin("admin","123","张三","男","2000-04-04",new String[]{"1","2","3"},"1"));

        //学生数据初始化
        students.add(new Student("小明","18","男",76d));
        students.add(new Student("小红","20","女",89d));
        students.add(new Student("小刚","17","男",80d));

        for (Student student : students) {
            studentClasses.add(new StudentClass(student,null));
        }
        studentClasses.get(0).setStudentClass("1");
        studentClasses.get(1).setStudentClass("2");

    }

    public static int[] getSize() {
        return size;
    }

    public static void setSize(int[] size) {
        DaoUtils.size = size;
    }

    //添加到用户列
    public static void addAdmins(Admin admin){
        admins.add(admin);
    }
    //添加到学生列
    public static void addStudents(Student student){
        students.add(student);
        studentClasses.add(new StudentClass(student,null));
    }

    //添加到学生班级管理列
    public static void addStudentClasses(StudentClass studentClass){
        studentClasses.add(studentClass);
    }

    //删除学生列
    public static boolean deleteStudents(String name){
        for (Student student : new ArrayList<Student>(students)) {
            if (name.equals(student.getName())) {
                students.remove(student);
                return true;
            }
        }
        return false;
    }
    //获得学生列
    public static List<Student> getStudents(){
        return new ArrayList<>(students);
    }
    //获得用户列
    public static List<Admin> getAdmins(){return admins;}

    //传入管理员用户名和密码，数据库对比检验，返回管理员账户结果
    public static Admin checkAdmin(String username,String password){
        for(Admin admin:admins){
            if(admin.getUsername().equals(username)&&admin.getPassword().equals(password)){
                return admin;
            }
        }
        return null;
    }

    //获得学生管理列
    public static  List<StudentClass> getStudentClasses(){
        return studentClasses;
    }


}
